package com.example.javaui.slice.component;

import com.example.javaui.ResourceTable;
import com.example.javaui.Utils;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import ohos.global.resource.Resource;

public class ButtonSlice extends AbilitySlice {

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_slice_component_button);

        Button button = (Button) findComponentById(ResourceTable.Id_button);
        button.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Utils.log("我已经被单击!");
            }
        });

        RadioContainer radioContainer = (RadioContainer) findComponentById(ResourceTable.Id_radio_container);
        radioContainer.setMarkChangedListener(new RadioContainer.CheckedStateChangedListener() {
            @Override
            public void onCheckedChanged(RadioContainer radioContainer, int i) {
                Utils.log("被选择的选项为：第" + (i+1)+ "个选项");
            }
        });

        Switch switch1 = (Switch) findComponentById(ResourceTable.Id_switch1);
        switch1.setChecked(true);

        ToggleButton toggleButton = (ToggleButton) findComponentById(ResourceTable.Id_togglebutton);
        toggleButton.setChecked(true);
    }
}
